import Friut from './Friut.js';
import Enemy from './Enemy.js';


class Pool{
  constructor(ctx, handcart){
    this.ctx = ctx;
    this.handcart = handcart;
    this.handcarts = [];
    this.friuts =[];
    this.enemys = [];
    this.score = 0;
  }
  drawFriuts(top){
     //批量绘制水果
    if(top % 40 ==0){
      //垂直方向每移动40 距离就产生水果
      const friut = new Friut(this.ctx);
      this.friuts.push(friut);
    }
    //过滤飞出的水果
    this.friuts = this.friuts.filter(item =>{
      //销毁飞出的水果
      return item.status ===true;
    })
    //批量绘制水果
    this.friuts.forEach(friut =>{
      friut.draw();
      this.friuts.forEach(friut => {
        //判断每一颗水果和箩筐是否相撞
        let flag = this.handcart.isCatch(friut);
        if (flag) {
          this.score += 1;
          // console.log(this.score);
          friut.status = false;
        }
      })
    })
  }
  drawEnemys(top){
    if(top % 35 ==0){
      const enemy = new Enemy(this.ctx);
      this.enemys.push(enemy);
    }
    this.enemys = this.enemys.filter(item =>{
      return item.status ===true;
    })
    //批量绘制水果
    this.enemys.forEach(enemy => {
      enemy.draw();
      //判断是否相撞
      let flags = this.handcart.gameOver(enemy);
      if(flags){
        friut.status = true;
        this.score = this.score +0;
      }
    })
  }
}
export default Pool;